package team.seekers.hula.course.resource.problemSubmit.entity.dao;

import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import org.springframework.beans.BeanUtils;
import team.seekers.hula.common.entity.BaseDO;
import team.seekers.hula.course.resource.problemSubmit.entity.dto.SubmissionDetailDTO;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 题库提交表(EduSubmission)实体类
 *
 * @author GH
 * @since 2022-05-02 19:57:18
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(SubmissionDOField.TABLE_NAME)
public class SubmissionDO extends BaseDO {
    /**
     * 主键, 分布式id
     */
    @TableId(value = SubmissionDOField.ID, type = IdType.AUTO)
    private Long id;
    /**
     * 题目id
     */
    @TableField(SubmissionDOField.PROBLEM_ID)
    private Long pId;
    /**
     * 提交者id
     */
    @TableField(SubmissionDOField.USER_ID)
    private Long uId;
    /**
     * 关联的单元测试id
     */
    @TableField(SubmissionDOField.EXAM_ID)
    private Long exId;
    /**
     * 提交端ipv4
     */
    @TableField(SubmissionDOField.IPV4)
    private String ipv4;
    /**
     * 提交结果
     */
    @TableField(SubmissionDOField.RESULT)
    private String result;
    /**
     * 评测分数
     */
    @TableField(SubmissionDOField.SCORE)
    private Float score;
    /**
     * 第几次提交
     */
    @TableField(SubmissionDOField.COUNT)
    private Integer count;
    /**
     * 有效提交, 0无效, 1有效
     */
    @TableField(SubmissionDOField.VALID)
    private Integer valid;
    /**
     * 是否公开, 0不公开, 1公开
     */
    @TableField(SubmissionDOField.IS_PUBLIC)
    private Integer isPublic;

    @TableField(SubmissionDOField.DELETED)
    @TableLogic(value = "0", delval = "1")
    private Integer deleted;

    @TableField(SubmissionDOField.VERSION)
    @Version
    private Integer version;

    @TableField(value = SubmissionDOField.GMT_CREATE, fill = FieldFill.INSERT)
    private Date gmtCreate;

    @TableField(value = SubmissionDOField.GMT_MODIFIED, fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;


    public static List<SubmissionDetailDTO> toDTOList(List<SubmissionDO> submissionDOS){
        ArrayList<SubmissionDetailDTO> submissionDetailDTOS = new ArrayList<>();
        for (SubmissionDO submissionDO : submissionDOS) {
            SubmissionDetailDTO submissionDetailDTO = new SubmissionDetailDTO();
            BeanUtils.copyProperties(submissionDO,submissionDetailDTO);
            submissionDetailDTOS.add(submissionDetailDTO);
        }
        return submissionDetailDTOS;
    }
}
